package com.qianli.cashmama.trade.openApi;

import com.qianli.cashmama.trade.openApi.enums.MerchantEnum;
import com.qianli.cashmama.trade.openApi.enums.OpenApiErrorCodeEnum;
import com.qianli.cashmama.trade.openApi.exception.OpenApiException;
import com.qianli.cashmama.trade.openApi.vendor.inner.request.InnerPushRequest;
import com.qianli.cashmama.trade.openApi.vendor.SynchronizationBaseHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: sm
 * Date: 2020-11-30
 * Time: 14:07
 * <p>
 * <p>
 * 提供一推 二推接口
 */
@Service
public class TradeSynchronizationService {


    public static Map<MerchantEnum, SynchronizationBaseHandler> merchantEnumSynchronizationBaseHandlerMap = new HashMap<>();
    public static Map<MerchantEnum, String> pushUrlMap = new HashMap<>();


    public boolean dataSync(MerchantEnum merchantEnum, InnerPushRequest request) {
        if (!merchantEnumSynchronizationBaseHandlerMap.containsKey(merchantEnum)) {
            throw new OpenApiException(OpenApiErrorCodeEnum.Handler_not_exist.getCode());
        }

       return  merchantEnumSynchronizationBaseHandlerMap.get(merchantEnum).dataSynchronization(request);
    }
}
